package com.shiwu.server.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 作者：LCG
 * 创建时间：2019/4/2 18:16
 * 描述：
 */
@Component
public class ServerService {

    @Autowired
    private ServerMapper serverMapper;

    @Transactional
    public int updateKucun(Map<String,Object> map){

        //查询日志
        List<Map<String, Object>> orderLog = serverMapper.getOrderLog ( map );

        if(orderLog.size ()>0){
           return 1;
        }else{
           //更新库存
           int i = serverMapper.updateKucun ( map );
           if(i==1){
               //写入一条日志
               Map<String,Object> log=map;
               log.put ( "orderId",map.get ( "id" ) );
               log.put ( "id",UID.getUUIDOrder () );
               serverMapper.insertOrderLog ( log );
           }

           if(map.get ( "error" )!=null){
               throw new RuntimeException ( "=========业务出错==========" );
           }

           return i;
        }

    }

}
